package com.chen.mobiletwo.service;

import com.chen.mobiletwo.dao.PanDao;
import com.chen.mobiletwo.entity.ResultEntity;
import jakarta.annotation.Resource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

@Service
public class PanService {
    private static final Logger logger= LoggerFactory.getLogger(PanService.class);//日志getLogger需要传入的类名
    @Resource
    PanDao panDao;

    /**
     * 无条件查询列表
     * @return String
     */
    public String getPanList (){
        try{
            return ResultEntity.success(panDao.getPanList());
        }catch (Exception e){
            logger.error(e.getLocalizedMessage());
            return ResultEntity.fail(-10004);
        }
    }
    /**
     * 根据id删除
     * @param pId id
     * @return String
     */
    public String delPan(int pId){
        try{
            return ResultEntity.success(panDao.delPan(pId));
        }catch (Exception e){
            logger.error(e.getLocalizedMessage());
            return ResultEntity.fail(-10004);
        }
    }

    /**
     * 根据id 修改所有数据
     * @param pId id
     * @param pName 名字
     * @param pweChat 微信
     * @param pqqNum qq
     * @return String
     */
    public String upPan(int pId,String pName,String pweChat,String pqqNum){
        try{
            return ResultEntity.success(panDao.upPan(pId,pName,pweChat,pqqNum));
        }catch (Exception e){
            logger.error(e.getLocalizedMessage());
            return ResultEntity.fail(-10004);
        }
    }

    /**
     * 添加数据
     * @param pName 名字
     * @param pweChat 微信
     * @param pqqNum qq
     * @return
     */
    public String addPan(String pName,String pweChat,String pqqNum){
        try{
            return ResultEntity.success(panDao.addPan(pName,pweChat,pqqNum));
        }catch (Exception e){
            logger.error(e.getLocalizedMessage());
            return ResultEntity.fail(-10004);
        }
    }
}
